package com.zhf.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
import org.springframework.stereotype.Component;

/**
 * @author: 曾鸿发
 * @create: 2022-01-10 15:26
 * @description：
 **/
@Component
public class QosListener implements ChannelAwareMessageListener {

    @Override
    public void onMessage(Message message, Channel channel) throws Exception {

        // 1. 获取到的消息
        System.out.println(new String(message.getBody()));
        // 处理业务逻辑

        Thread.sleep(1000);

        // 进行消息的签收
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
    }
}
